<template>
  <div>
    <router-view></router-view>
  </div>
</template>
<script type="text/ecmascript-6">
import navbar from 'components/navbar/navbar';
const ERR_OK = 1;
export default {
  props: {
  },
  created() {
    window.localStorage.openid = 'ovlaLw8Qk5w63z4jO5M0zWRwFFRI';
    let url = encodeURI('http://cw.lightway.cc' + this.$route.fullPath);
    if (!window.localStorage.openid && !this.$route.query.code) {
    window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxcc0958c36b0ec404&redirect_uri=' + url + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
    }
    if (this.$route.query.code) {
      this.$http.get('http://cj.lightway.cc/api/pay/getopenid?code=' + this.$route.query.code).then((response) => {
        response = response.body;
        if (response.errno === ERR_OK) {
          window.localStorage.openid = response.openid;
          window.alert(response.openid);
        } else {
          window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxcc0958c36b0ec404&redirect_uri=' + url + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
        }
      });
    }
  },
  components: {
    navbar
  }
};
</script>
<style lang="stylus" rel="stylesheet/stylus">
  /*主要文字 黑 main-fn
  次要文字 灰 se-fn
  预填文字 灰 pre-fn
  描边 灰 border 
  背景 灰白 bg 
  主题 红 theme
  辅助 蓝 assist
  背景 白 bg-white */
	


</style>
